home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / kernel / fsutil / fsutilSync.c < prev   
Encoding:
C/C++ Source or Header  |  1992-12-19  |  4.8 KB  |  199 lines

  1. /* 
  2.  * fsutilSync.c --
  3.  *
  4.  * Routines controlling the syncing of cached data to disk or the server.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /cdrom/src/kernel/Cvsroot/kernel/fsutil/fsutilSync.c,v 9.3 91/09/10 18:24:24 rab Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20.  
  21. #include <sprite.h>
  22.  
  23. #include <fs.h>
  24. #include <vm.h>
  25. #include <rpc.h>
  26. #include <fsutil.h>
  27. #include <fsdm.h>
  28. #include <fslcl.h>
  29. #include <fsNameOps.h>
  30. #include <fsprefix.h>
  31. #include <fsStat.h>
  32. #include <sync.h>
  33. #include <timer.h>
  34. #include <proc.h>
  35. #include <hash.h>
  36. #include <fsrmt.h>
  37.  
  38. #include <stdio.h>
  39.  
  40. #define    MAX_WAIT_INTERVALS    5
  41.  
  42.  
  43. Boolean fsutil_ShouldSyncDisks;
  44.  
  45. int        fsWriteBackInterval = 30;    /* How long blocks have to be
  46.                          * dirty before they are
  47.                          * written back. */
  48. int        fsWriteBackCheckInterval = 5;    /* How often to scan the
  49.                          * cache for blocks to write
  50.                          * back. */
  51. Boolean        fsutil_ShouldSyncDisks = TRUE;    /* TRUE means that we should
  52.                          * sync the disks when
  53.                          * Fsutil_SyncProc is called. */
  54. int        lastHandleWBTime = 0;        /* Last time that wrote back
  55.                          * file handles. */
  56. /*
  57.  *----------------------------------------------------------------------
  58.  *
  59.  * Fsutil_SyncProc --
  60.  *
  61.  *    Process to loop and write back things every thiry seconds.
  62.  *
  63.  * Results:
  64.  *    None.
  65.  *
  66.  * Side effects:
  67.  *    None.
  68.  *
  69.  *----------------------------------------------------------------------
  70.  */
  71. /*ARGSUSED*/
  72. void
  73. Fsutil_SyncProc(data, callInfoPtr)
  74.     ClientData        data;        /* IGNORED */
  75.     Proc_CallInfo    *callInfoPtr;
  76. {
  77.     int    blocksLeft;
  78.  
  79.     if (Fsutil_TimeInSeconds() - lastHandleWBTime >= fsWriteBackInterval) {
  80.     (void) Fsutil_HandleDescWriteBack(FALSE, -1);
  81.     lastHandleWBTime = Fsutil_TimeInSeconds();
  82.     }
  83.  
  84.     if (fsutil_ShouldSyncDisks) {
  85.     Fscache_WriteBack((unsigned) (Fsutil_TimeInSeconds() -
  86.         fsWriteBackInterval), &blocksLeft, FALSE);
  87.     }
  88.     if (fsWriteBackCheckInterval < fsWriteBackInterval) {
  89.     callInfoPtr->interval = fsWriteBackCheckInterval * timer_IntOneSecond;
  90.     } else {
  91.     callInfoPtr->interval = fsWriteBackInterval * timer_IntOneSecond;
  92.     }
  93.  
  94. }
  95.  
  96.  
  97. /*
  98.  *----------------------------------------------------------------------
  99.  *
  100.  * Fsutil_Sync --
  101.  *
  102.  *    Write back bit maps, file descriptors, and all dirty cache buffers.
  103.  *
  104.  * Results:
  105.  *    None.
  106.  *
  107.  * Side effects:
  108.  *    None.
  109.  *
  110.  *----------------------------------------------------------------------
  111.  */
  112.  
  113. void
  114. Fsutil_Sync(writeBackTime, shutdown)
  115.     unsigned int writeBackTime;    /* Write back all blocks in the cache and file
  116.                        descriptors that were dirtied before 
  117.                    this time. */
  118.     Boolean    shutdown;    /* TRUE if the kernel is being shutdown. */
  119. {
  120.     int        blocksLeft = 0;
  121.     /*
  122.      * Force all file descriptors into the cache.
  123.      */
  124.     (void) Fsutil_HandleDescWriteBack(shutdown, -1);
  125.     /*
  126.      * Write back the cache.
  127.      */
  128.     Fscache_WriteBack(writeBackTime, &blocksLeft, shutdown);
  129.     if (shutdown) {
  130.     if (blocksLeft) {
  131.         printf("Fsutil_Sync: %d blocks still locked\n", blocksLeft);
  132.     }
  133. #ifdef notdef
  134.     Fscache_CleanBlocks((ClientData) FALSE, (Proc_CallInfo *) NIL);
  135. #endif
  136.     }
  137.     /*
  138.      * Finally write all domain information to disk.  This will mark each
  139.      * domain to indicate that we went down gracefully and recovery is in
  140.      * fact possible.
  141.      */
  142.     Fsdm_DomainWriteBack(-1, shutdown, FALSE);
  143. }
  144.  
  145. /*
  146.  *----------------------------------------------------------------------
  147.  *
  148.  * Fsutil_SyncStub --
  149.  *
  150.  *    Procedure bound to the L1-w keystoke.  This is called at
  151.  *    keyboard interrupt time and so it makes a Proc_CallFunc
  152.  *    to invoke the Fsutil_Sync procedure.
  153.  *
  154.  * Results:
  155.  *    None.
  156.  *
  157.  * Side effects:
  158.  *    Attempts to sync the disks.
  159.  *
  160.  *----------------------------------------------------------------------
  161.  */
  162. void SyncCallBack();
  163.  
  164. void
  165. Fsutil_SyncStub(data)
  166.     ClientData        data;
  167. {
  168.     printf("Queueing call to Fsutil_Sync() ... ");
  169.     Proc_CallFunc(SyncCallBack, data, 0);
  170. }
  171.  
  172.  
  173. /*
  174.  *----------------------------------------------------------------------
  175.  *
  176.  * Fs_SyncCallBack --
  177.  *
  178.  *    Procedure called via Proc_CallFunc to sync the disks.
  179.  *
  180.  * Results:
  181.  *    None.
  182.  *
  183.  * Side effects:
  184.  *    Syncs the disk.
  185.  *
  186.  *----------------------------------------------------------------------
  187.  */
  188. void
  189. SyncCallBack(data, callInfoPtr)
  190.     ClientData        data;
  191.     Proc_CallInfo    *callInfoPtr;
  192. {
  193.     printf("Syncing disks");
  194.     Fsutil_Sync(-1, (Boolean)data);
  195.     callInfoPtr->interval = 0;
  196.     printf(".\n");
  197. }
  198.  
  199.